﻿<%@ Page Title="" ValidateRequest="false" Language="C#" MasterPageFile="~/My/My.master" AutoEventWireup="true" CodeBehind="Album.aspx.cs" Inherits="OpenPhotoAlbum.My.Album" %>
<%@ Register Assembly="OpenPhotoAlbum" Namespace="OpenPhotoAlbum.Controls" TagPrefix="cc" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ph1" runat="server">

	<asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server">
		<Scripts>
			<asp:ScriptReference Path="~/Controls/CommonScripts.js" />
		</Scripts>
	</asp:ScriptManagerProxy>

	<asp:HiddenField ID="hfAlbumId" runat="server" />
	<asp:HiddenField ID="hfAlbumTitle" runat="server" />

	<script language="javascript" type="text/javascript">
		var albumId = null;
		var albumTitle = null;
		function setGlobalVars() {
			albumId = $('#<%= hfAlbumId.ClientID %>').val();
			albumTitle = $('#<%= hfAlbumTitle.ClientID %>').val();
		}
		Sys.Application.add_load(setGlobalVars);
		
		function textChanged(sender, e) {
			var photoId = e.contextData1;
			var linkClientId = e.contextData2;
			var text = e.newText;
			var context = new Array(photoId, sender._labelElement.id, linkClientId, text);
			OpenPhotoAlbum.My.Photos.UpdatePhotoTitleWithReturn(photoId, text, albumId, albumTitle, onSuccess, onFail, context);
			sender._labelElement.innerHTML = "<%= Resources.Strings.Saving %>";
		}
		function onSuccess(result, context) {
			var photoId = context[0];
			var labelClientId = context[1];
			var linkClientId = context[2];
			var text = context[3];
			setText($get(labelClientId), text);
			$('#' + linkClientId).attr('href', result);
		}
		function onFail(param) {}
		
		function showUploadDiv() {
		    $get('upload').style.display = '';
		    $get('wait').style.display = 'none';
		}
		function showWaitDiv() {
			$get('upload').style.display = 'none';
			$get('wait').style.display = '';
		}
		function showUploadDivAsNeeded() {
			var afterUploading = '<%= this.AfterUploading %>';
			if (afterUploading == 'True') { showUploadDiv(); }
		}
		Sys.Application.add_load(showUploadDivAsNeeded);

		function hideUploadBlock() {
			$get('upload').style.display = 'none';
			$get('wait').style.display = 'none';
		}
		function copy() {
			var addr = getText($get('address'));
			copyToClipboard(addr);
		}
		function onKeyDown(e) {
			if (e.keyCode == 13) { $get('<%= btnUpload.ClientID %>').click(); }
		}
		function bindKeyDownEvent() {
			$addHandler($get('<%= tbCaption.ClientID %>'), 'keydown', onKeyDown);
		}
		Sys.Application.add_load(bindKeyDownEvent);
		$(function() {
			if (jQuery.browser.safari || jQuery.browser.mozilla) {
				adjust();
				Sys.WebForms.PageRequestManager.getInstance().add_endRequest(adjust);
			}
		});
		function adjust() {
			if (jQuery.browser.safari) {
				$('table.item').each(function() { $(this).css('display', 'inline-table'); });
			}
			else if (jQuery.browser.mozilla) {
				$('table.item').each(function() { $(this).css('display', 'inline-block'); });
			}
		}
		function showPhotos() { $('div.photos').css('display', ''); }
		Sys.Application.add_load(showPhotos);
	</script>
	
	<div class="album"><div class="photos">
	
		<cc:TabPanels ID="tabPanels" runat="server" />
	
		<cc:TabPanel ID="pnlUpload" runat="server">
			<div id="upload" class="upload">
				<div class="hint"><%= StringUtility.AddColon(Resources.Strings.My_UpdatePhotoToCurrentAlbum) %></div>
				<table>
					<tr>
						<td style="text-align:right"><asp:Literal ID="lblSelectPhotoFile" runat="server" /></td>
						<td><asp:FileUpload ID="fileUpload" runat="server" CssClass="fileUpload" /></td>
					</tr>
					<tr>
						<td style="text-align:right"><asp:Literal ID="lblCaption" runat="server" /></td>
						<td><asp:TextBox ID="tbCaption" runat="server" CssClass="caption" onkeydown="onKeyDown" /></td>
					</tr>
					<tr>
						<td colspan="2" style="text-align:right">
							<asp:Button ID="btnUpload" runat="server" OnClientClick="javascript:showWaitDiv();" CssClass="submit" />
						</td>
					</tr>
				</table>
			</div>
			<div id="wait" style="display:none;" class="wait">
				<asp:Label ID="lblWait" runat="server" CssClass="waitText" />
			</div>
		</cc:TabPanel>
		<cc:TabPanel ID="pnlSharingAddress" runat="server" CssClass="sharingAddress">
			<div class="explanation"><%= Resources.Strings.SharingAddress_Explanation %></div>
			<div id="address" class="address"><asp:Literal ID="ltrSharingAddress" runat="server" /></div>
			<div class="btn">
				[<asp:HyperLink ID="hlVisit" runat="server" Target="_blank" />]
				[<a href="javascript:copy();"><%= Resources.Strings.CopyToClipboard %></a>]
			</div>
		</cc:TabPanel>

		<div style="height:1px;"></div>

		<%--UpdatePanel: Main--%>
		<asp:UpdatePanel ID="upPhotos" runat="server" UpdateMode="Always"><ContentTemplate>

			<asp:Repeater ID="rptPhotos" runat="server">
				<ItemTemplate>
					<table class="item" cellpadding="0" cellspacing="0"><tr><td>
						<span class="thumbnail"><asp:HyperLink ID="hlPhoto" runat="server"><asp:Image ID="imgPhoto" runat="server" /></asp:HyperLink></span>
						<span class="itemTitle"><cc:InplaceEditLabel ID="lblCaption" runat="server" OnClientTextChanged="textChanged" /></span>
						<span class="creationDate"><asp:Label ID="lblCreationDate" runat="server" /></span>
						<span class="commands">
							<cc:AlbumCommandLinkButton ID="linkBtnDelete" runat="server" />
							<cc:AlbumCommandLinkButton ID="linkBtnCover" runat="server" />
						</span>
					</td></tr></table>
					<cc:TooltipExtender ID="ttCaption" runat="server" TargetControlID="lblCaption" Position="Right" />
					<cc:TooltipExtender ID="ttDelete" runat="server" TargetControlID="linkBtnDelete" />
					<cc:TooltipExtender ID="ttCover" runat="server" TargetControlID="linkBtnCover" />
				</ItemTemplate>
			</asp:Repeater>

		</ContentTemplate></asp:UpdatePanel>
	
	</div></div>

</asp:Content>
